package com.stn.zjx.givingtreasure.net.impl;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.stn.zjx.givingtreasure.net.BaseApi;

import java.util.HashMap;
import java.util.Map;


public class BaseNetImpl {
    /**
     *
     * @param tag 网络请求标签
     * @param callback 请求回调
     */
    public static void get_webIp(String tag,StringCallback callback){
        OkGo.<String>get(BaseApi.webip_url)
                .tag(tag)
                .execute(callback);
    }

    /**
     * @apiNote 通过code,获取微信授权信息
     * @param code 获取唯一码
     * @param appkey appkey
    * @param appkey appsecret
     * @param tag 标签
     * @param callback 请求回调
     */
    public static void wx_getToken(String code,String appkey,String appsecret,String tag,StringCallback callback){
            Map<String,String> map=new HashMap<>();
            map.put("appid",""+appkey);
            map.put("secret",""+appsecret);
             map.put("code",""+code);
            map.put("grant_type","authorization_code");
        OkGo.<String>get(BaseApi.wx_getToken)
                .tag(tag)
                .params(map)
                .execute(callback);

    }

    /**
     * @apiNote 通过token，获取微信用户信息
     * @param access_token token
     * @param openid 用户唯一ID
     * @param tag 标签
     * @param callback 请求回调
     */
    //微信获取用户基本信息
    public static void wx_getInfo(String access_token,String openid,String tag,StringCallback callback){
        Map<String,String> map=new HashMap<>();
        map.put("access_token",""+access_token);
        map.put("openid",""+openid);

        OkGo.<String>get(BaseApi.wx_getInfo)
                .tag(tag)
                .params(map)
                .execute(callback);

    }
}
